{include file="/public/header"}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" id="formBasForm" lay-filter="formBasForm">
                <input name="id" type="hidden"/>
                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">应用配置</li>
                        <li>系统配置</li>
                        <li>价格配置</li>
                        <li>授权配置</li>
                        <li>盗版配置</li>
                        <li>公告配置</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="height: 32px;border-radius: 4px;">应用名称</label>
                                <div class="layui-input-block">
                                    <input type="text" style="border-radius: 0px 4px 4px 0px;" name="name" class="layui-input" placeholder="应用的名称"/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">应用LOGO</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" name="logo" placeholder="填写图片URL，没有默认为系统LOGO">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-upload-drag" id="upload">
                                    <i class="layui-icon layui-icon-upload-drag" style="color:#2d8cf0;"></i>
                                    <p>点击上传，或将文件拖拽到此处</p>
                                    <div class="layui-hide" id="uploadDemoView">
                                        <hr>
                                        <img src="" alt="上传成功后渲染" id="demo1" style="max-width: 196px">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">应用简介</label>
                                <div class="layui-input-block">
                                    <textarea name="introduce" class="layui-textarea" style="height:100px" placeholder="该应用的简单介绍,可留空"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">判断规则</label>
                                <div class="layui-input-block">
                                    <select class="layui-input" name="check_type" lay-filter="check_type" lay-search>
                                        <option value="">请选择判断规则</option>
                                        {volist name="check_type_list" id="res"}
                                        <option value="{$res.type}">{$res.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">应用状态</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="status" value="2" title="正常运营" checked>
                                    <input type="radio" name="status" value="1" title="系统维护">
                                    <input type="radio" name="status" value="0" title="停止运营">
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">授权查询</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="auth_query_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">代理查询</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="user_query_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">支付查询</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="pay_query_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">自助注册</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="register_switch" value="1" lay-filter="register_switch" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">自助授权</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="auth_query_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">卡密兑换</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="cdkey_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">更换授权</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="replace_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">更换次数</label>
                                <div class="layui-input-block">
                                    <input type="number" name="free_replace_number" class="layui-input" placeholder="免费更换授权的次数"/>
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">API接口</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="api_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">认证易支付</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="pay_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">绑定授权</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="binding_auth_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">绑定认证</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="binding_payment_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">API密钥</label>
                                <div class="layui-input-block">
                                    <input type="number" name="API_KEY" class="layui-input" placeholder="调用本应用API时的密钥"/>
                                </div>
                            </div>
                            <div id="register_blacklist">
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">注册黑名单</label>
                                    <div class="layui-input-block">
                                        <textarea name="register_blacklist" class="layui-textarea" style="height:100px" placeholder="多个IP用|隔开"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>授权价格配置</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">价格模板</label>
                                        <div class="layui-input-block">
                                            <select id="auth_template" class="layui-input" name="auth_template" lay-search>
                                                <option value="">请选择价格模板</option>
                                                <option value="1">默认模板</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <div id="payrmb">
                                <fieldset class="layui-elem-field layui-field-title">
                                    <legend>认证价格配置</legend>
                                    <div class="layui-field-box">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">价格模板</label>
                                            <div class="layui-input-block">
                                                <select id="payment_template" class="layui-input" name="payment_template" lay-search>
                                                    <option value="">请选择价格模板</option>
                                                    <option value="1">默认模板</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>权限价格配置</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">价格模板</label>
                                        <div class="layui-input-block">
                                            <select id="power_template" class="layui-input" name="power_template" lay-search>
                                                <option value="">请选择权限模板</option>
                                                <option value="1">默认模板</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>其他价格配置</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">查看盗版</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="pirate_money" class="layui-input" placeholder="代理查看盗版站点信息时扣除的价格"/>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">赠送余额</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="give_money" class="layui-input" placeholder="该应用的代理添加下级代理时,下级代理初始的余额"/>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">更换价格</label>
                                        <div class="layui-input-block">
                                            <input type="number" name="replace_money" class="layui-input" placeholder="免费更换次数用完的更换价格"/>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">公钥</label>
                                <div class="layui-input-block">
                                    <textarea name="public_key" class="layui-textarea" style="height:100px" placeholder="这里填写生成后的公钥"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">私钥</label>
                                <div class="layui-input-block">
                                    <textarea name="private_key" class="layui-textarea" style="height:100px" placeholder="这里填写生成后的私钥"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="sf-tips">
                                    公钥私钥生成地址：<a href="https://www.bejson.com/enc/rsa/" target="_blank">https://www.bejson.com/enc/rsa/</a>
                                </div>
                            </div>

                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">在线更新</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="update_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">盗版入库</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="pirate_switch" value="0" title="关闭" checked>
                                    <input type="radio" name="pirate_switch" value="1" title="盗版入库">
                                    <input type="radio" name="pirate_switch" value="2" title="全部入库">
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">检测IP</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="ip_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">检测授权码</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="authcode_switch" value="1" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item" pane>
                                <label class="layui-form-label">提交方式</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="check_auth_method" value="1" lay-text="POST|GET" lay-skin="switch" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">验证文件</label>
                                <div class="layui-input-block">
                                    <input type="text" name="authcode_file" class="layui-input" placeholder="请填写您应用authcode.php的位置，例如includes/authcode.php" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">更新SQL</label>
                                <div class="layui-input-block">
                                    <input type="text" name="sql_file" class="layui-input" placeholder="请填写您应用update.sql的位置，例如install/update.sql"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div id="blocktext">
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">盗版提示</label>
                                    <div class="layui-input-block">
                                        <textarea name="pirate_msg" class="layui-textarea" style="height:100px" placeholder="该应用的盗版提示 例如 您当前未授权，请联系xxx授权" ></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">授权到期提示</label>
                                    <div class="layui-input-block">
                                        <textarea name="endtime_msg" class="layui-textarea" style="height:100px" placeholder="该应用的到期提示 例如 您当前授权已到期，请联系xxx续费" ></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">授权封禁提示</label>
                                    <div class="layui-input-block">
                                        <textarea name="status_msg" class="layui-textarea" style="height:100px" placeholder="该应用的封禁提示 例如 您当前授权已被封禁，请联系xxx解封" ></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">授权码错误提示</label>
                                    <div class="layui-input-block">
                                        <textarea name="authcode_msg" class="layui-textarea" style="height:100px" placeholder="该应用的授权码错误提示 例如 您当前授权码错误，请联系xxx获取" ></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">IP错误提示</label>
                                    <div class="layui-input-block">
                                        <textarea name="ip_msg" class="layui-textarea" style="height:100px" placeholder="该应用的IP错误提示 例如 您当前IP与授权IP不符，请联系xxx更改" ></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">后门地址</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="hacker_file" class="layui-input" placeholder="请填写您应用的后门访问地址"/>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">后门密码</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="hacker_key" class="layui-input" placeholder="请填写您应用的后门访问密码"/>
                                    </div>
                                </div>
                                <div class="layui-form-item" pane>
                                    <label class="layui-form-label">盗版提示</label>
                                    <div class="layui-input-block">
                                        <input type="checkbox" name="pirate_msg_switch" value="1" lay-skin="switch" />
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">应用公告</label>
                                <div class="layui-input-block">
                                    <textarea name="app_notice" class="layui-textarea" style="height:100px" placeholder="该应用的公告，可留空" ></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">卡密兑换公告</label>
                                <div class="layui-input-block">
                                    <textarea name="cdkey_notice" class="layui-textarea" style="height:100px" placeholder="该应用卡密兑换时的公告" ></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">余额充值公告</label>
                                <div class="layui-input-block">
                                    <textarea name="pay_notice" class="layui-textarea" style="height:100px" placeholder="该应用余额充值时的公告" ></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">用户自助注册公告</label>
                                <div class="layui-input-block">
                                    <textarea name="register_notice" class="layui-textarea" style="height:100px" placeholder="该应用用户自助注册时的公告" ></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">更换授权公告</label>
                                <div class="layui-input-block">
                                    <textarea name="replace_notice" class="layui-textarea" style="height:100px" placeholder="该应用更换授权时的公告" ></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr style="width:0px"><hr>
                    <div class="layui-form-item">
                        <div class="layui-btn-container">
                            <button type="button" class="layui-btn" id="noticeBtn" lay-filter="submitBtn" lay-submit>&emsp;提交&emsp;</button>
                            <button type="reset" id="formreset" class="layui-btn layui-btn-primary">&emsp;重置&emsp;</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{include file="/public/footer"}
<script>
    layui.use(['upload', 'admin', 'form', 'element','jquery', 'notice'], function () {
        var form = layui.form;
        var upload = layui.upload;
        var $ = layui.jquery;
        var notice = layui.notice;
        var element = layui.element;
        var admin = layui.admin;
        admin.iframeAuto();

        var appInfoData = JSON.parse(JSON.stringify(admin.getLayerData()));
        if(!appInfoData.sf){
            $("input[name='logo']").val(appInfoData.logo);
            layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', appInfoData.logo);
            form.val('formBasForm', appInfoData);
            form.render();
        }

        notice.msg('正在获取列表中..', {icon: 4, close: true});
        $.ajax({
            type: "POST",
            url: '{:url("/AuthTemplate/getList")}',
            dataType: "json",
            success: function(data) {
                notice.destroy();
                if (data.code == 0) {
                    notice.msg("获取列表成功！", {icon: 1, audio:'1'});
                    var content = '<option value="">请选择所属模板</option>';
                    $.each(data.data,function(index, value){
                        $.each(value,function(index, value){
                            content += '<option value="'+value.id+'">'+value.name+'</option>';
                        });
                    });
                    $("#auth_template").html(content);
                    $("#payment_template").html(content);
                    if(!appInfoData.sf) {
                        form.val('formBasForm', appInfoData);
                    }
                } else {
                    notice.msg(data.msg, {icon: 2, audio:'1'});
                }
                form.render();
            },
            error: function() {
                notice.destroy();
                notice.msg("服务器错误！", {icon: 2, audio:'1'});
            }
        });

        notice.msg('正在获取列表中..', {icon: 4, close: true});
        $.ajax({
            type: "POST",
            url: '{:url("/PowerTemplate/getList")}',
            dataType: "json",
            success: function(data) {
                notice.destroy();
                if (data.code == 0) {
                    notice.msg("获取列表成功！", {icon: 1, audio:'1'});
                    var content = '<option value="">请选择所属模板</option>';
                    $.each(data.data,function(index, value){
                        $.each(value,function(index, value){
                            content += '<option value="'+value.id+'">'+value.name+'</option>';
                        });
                    });
                    $("#power_template").html(content);
                    if(!appInfoData.sf) {
                        form.val('formBasForm', appInfoData);
                    }
                } else {
                    notice.msg(data.msg, {icon: 2, audio:'1'});
                }
                form.render();
            },
            error: function() {
                notice.destroy();
                notice.msg("服务器错误！", {icon: 2, audio:'1'});
            }
        });

        var uploadInst = upload.render({
            elem: '#upload'
            ,url: '{:url("/Upload/image")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
                notice.msg('上传中...', {icon: 4, close: true});
            }
            ,done: function(res){
                notice.destroy();
                //如果上传失败
                if(res.code == 0){
                    $("input[name='logo']").val(res.data.path);
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.files.file);
                    notice.msg('上传成功！', {icon: 1, audio:'1'});
                }else{
                    notice.msg('上传失败！', {icon: 2, audio:'1'});
                }
            }
        });
        form.on('submit(submitBtn)', function (data) {
            if (data.field.name == "") {
                notice.msg('请输入应用名称！', {icon: 3, audio:'1'});
                return false;
            }
            if (data.field.public_key == "") {
                notice.msg('请填写授权公钥！', {icon: 3, audio:'1'});
                return false;
            }
            if (data.field.private_key == "") {
                notice.msg('请填写授权私钥！', {icon: 3, audio:'1'});
                return false;
            }
            if (data.field.pirate_msg == "") {
                notice.msg('请填写盗版提示内容！', {icon: 3, audio:'1'});
                return false;
            }
            if (data.field.endtime_msg == "") {
                notice.msg('请填写授权到期提示内容！', {icon: 3, audio:'1'});
                return false;
            }
            if (data.field.status_msg == "") {
                notice.msg('请填写授权封禁提示内容！', {icon: 3, audio:'1'});
                return false;
            }
            if (data.field.authcode_msg=="") {
                notice.msg('请填写授权码不正确提示内容！', {icon: 3, audio:'1'});
                return false;
            }
            notice.msg('正在执行中..', {icon: 4, close: true});
            $.ajax({
                type: "POST",
                url: "{:url('/App/edit')}",
                data: data.field,
                dataType: "json",
                success: function(data) {
                    notice.destroy();
                    if (data.code == 0) {
                        notice.msg(data.msg, {icon: 1, audio:'1'});
                    } else {
                        notice.msg(data.msg, {icon: 2, audio:'1'});
                    }
                }
            });
            return false;
        });
        form.on('switch(register_switch)', function (data) {
            if (data.elem.checked) {
                $("#register_blacklist").css("display","inherit");
            }else{
                $("#register_blacklist").css("display","none");
            }
        });
        $('#formreset').click(function () {
            $("#formBasForm")[0].reset();
            notice.msg('重置表单成功！', {icon: 1, audio:'1'});
        });
    });
</script>